var g_listcount = 0;

function h(obj){
	if($(obj)) $(obj).style.display = 'none';
}
function s(obj){
	if($(obj)) $(obj).style.display = '';
}

function addallfriendShowEx(req) {
	s("addfrienddiv");
	addfriendskip();
}

function addfriendskip() {
	$("reguserdiv").style.display = 'none';
	if (g_listcount) {
		s("listdiv");
	}
}

function accountAjaxShow(r) {
	$("gettingdiv").style.display = 'none';
	if(r == "error") {
		$("getempty").style.display = 'none';
		s("geterror");
	} else if(r == "empty") {
		$("geterror").style.display = 'none';
		s("getempty");
	} else {
		eval("r=" + r);
		g_listcount = r.list.length;
		
		$("regusercount").innerHTML = r.reg.length;
		if (r.list.length) {
			s('addfriendskip_btn');
			$('addfriendcancel_btn').style.display = 'none';
		} else {
			$('addfriendskip_btn').style.display = 'none';;
			s('addfriendcancel_btn');
		}
		
		var html = "<div style=\"width:100%; background:#ededed; padding-bottom:4px; border-bottom:#c0c0c0 1px solid;\"><input type=\"checkbox\" name=\"chkall\" onclick=\"javascript:checkAll($('reguidform'), 'reguid');\" checked>全选</div>";
		html += "<div style=\"width:100%; height:245px; background:#fff; overflow-x:hidden; overflow-y:scroll; margin:5px 0px; border: 1px solid #c0c0c0;\">";
		for (i=0; i<r.reg.length; i++){
			html += "<div onclick='click_check(this)'   onmouseover=\"this.style.background='#D9ECF3 none repeat scroll 0%';\" onmouseout=\"this.style.background='"+(i % 2 == 0 ? "#ffffff" : "#f5f5f5")+" none repeat scroll 0%';\"  style=\"float:left; width:100%; padding:10px 0 5px 0; background:" + (i % 2 == 0 ? "#ffffff" : "#f5f5f5") + ";\">" +
				"	<div style=\"float:left;\"><input onclick=\"try{event.cancelBubble=true;}catch(e){event.stopPropagation();}\" type=\"checkbox\" name=\"reguid\" value=\"" + r.reg[i].uid + "\" checked></div>" +
				"	<div style=\"float:left; width:50px; margin:0px 5px;\"><a target=\"_blank\" href=\"space.php?uid=" + r.reg[i].uid + "\" title=\"" + r.reg[i].user_name + "\"><img src=\"" + r.reg[i].icon + "\" style=\"width:50px; height:50p; border:0px;\"></a></div>" +
				"	<div style=\"float:left;\">" + r.reg[i].online + " <a target=\"_blank\" href=\"space.php?uid=" + r.reg[i].uid + "\" title=\"" + r.reg[i].user_name + "\">" + r.reg[i].user_name + "</a><br />" + (parseInt(r.reg[i].gender) ? "男&nbsp;":"女&nbsp;") + r.reg[i].city + "</div>" +
				"</div>"; 			
		}
		html += "</div>";
		$("reguserhtml").innerHTML = html;

		var html = "<div style=\"width:100%; background:#ededed; padding-bottom:4px; border-bottom:#c0c0c0 1px solid;\"><input type=\"checkbox\" name=\"chkall\" onclick=\"javascript:checkAll($('listform'), 'email');\" checked>全选</div>";
		html += "<div style=\"width:100%; height:245px; background:#fff; overflow-x:hidden; overflow-y:scroll; margin:5px 0px; border: 1px solid #c0c0c0;\">";
		for (i=0; i<r.list.length;i++){
			html += "<div onclick='click_check(this)' onmouseover=\"this.style.background='#D9ECF3 none repeat scroll 0%';\" onmouseout=\"this.style.background='"+(i % 2 == 0 ? "#ffffff" : "#f5f5f5")+" none repeat scroll 0%';\" style=\"float:left; width:100%;padding:4px 0 4px 0; background:" + (i % 2 == 0 ? "#ffffff" : "#f5f5f5") + ";\">" +
				"	<p style=\"float:left; width:55%;\"><input  onclick=\"try{event.cancelBubble=true;}catch(e){event.stopPropagation();}\" type=\"checkbox\" name=\"email\" value=\"" + r.list[i].email + "\" checked>" + r.list[i].nick + "</p>" +
				"	<p style=\"float:left;\">&lt;" + r.list[i].email + "&gt;</p>" +
				"</div>";
		}
		html += "</div>";
		$("checkdiv").innerHTML = html;
		
		if (r.reg.length) {
			s("listuser1");
		} else {
			s("listuser2");
		}
		if (r.list.length) {
			s("reguser1");
		} else {
			s("reguser2");
		}
		if (r.reg.length) {
			s("reguserdiv");
		} else {
			s("listdiv");
		}
		$("getdiv").style.display = 'none';
		s("showdiv");
	}
}
function click_check(obj)
{
	obj.getElementsByTagName('input')[0].checked = obj.getElementsByTagName('input')[0].checked ? false : true;
}
function invite_do() {
	var email_arr = new Array();
	for(var i = 0; i < $('listform').elements.length; i++) {
		var e = $('listform').elements[i];
		if(e.name.match('email') && e.checked) {
			email_arr.push(e.value);
		}
	}
	$('inviteform').emails.value = email_arr.join(",");;
	if ($('inviteform').emails.value.length == 0) {
		alert("请选择邀请对象");
		return;
	}
	if ($('listform').user_name.value.length == 0) {
		alert("请输入你的真实姓名！");
		$('listform').user_name.focus();
		return;
	}
	$('inviteform').user_name.value = $('listform').user_name.value;
	Form.submitDo('inviteform');
}

function trim(str) {
	return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1');
}
